package com.ruoyi.loginRecord.mapper;


import com.ruoyi.loginRecord.domain.CommonConfigInfoVo;
import com.ruoyi.loginRecord.domain.LoginRecord;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Map;

@Mapper
public interface LoginRecordOverrideMapper {

    @Select("SELECT * from sys_login_record limit 1")
    Map<String, Object> getInfo();

    @Select("select info from common_config where type = #{type}")
    CommonConfigInfoVo getCommonConfigInfo(@Param("type") String type);


    @Insert("insert into sys_login_record(user_id, user_name, ipaddr, login_location, browser, os, login_time, time_rule, parent_id, method, oper_url, oper_param, at_time)" +
            "values (#{userId}, #{userName}, #{ipaddr}, #{loginLocation}, #{browser}, #{os}, now(), #{timeRule}, #{parentId}, #{method}, #{operUrl}, #{operParam}, #{atTime} )")
    void insertLoginRecord(LoginRecord loginRecord);

    @Select("select id from sys_login_record where user_id = #{userId} and at_time = #{atTime} and parent_id = 0 order by login_time desc limit 1")
    Long getFirstRecord(@Param("atTime") String atTime, @Param("userId") Long userId);

}
